package com.ruoyi.common.enums.fission;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum GroupFissionStatusEnum {

    NOT_STARTED(0, "未开始"),
    IN_PROGRESS(1, "进行中"),
    ENDED(2, "已结束");

    private final Integer code;
    private final String desc;


    private static final Map<Integer, GroupFissionStatusEnum> ENUM_MAP;

    static {
        GroupFissionStatusEnum[] values = values();
        Map<Integer, GroupFissionStatusEnum> enToCn = new HashMap<>(values.length);
        for (GroupFissionStatusEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static GroupFissionStatusEnum getEnumByType(Integer type) {
        GroupFissionStatusEnum groupFissionStatusEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(groupFissionStatusEnum)) {
            throw new RuntimeException("类型有误");
        }
        return groupFissionStatusEnum;
    }

}
